﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
public partial class gupiaochi_BluePool : System.Web.UI.Page
{
    public string GetList = "";
    public string strPage = null;
    public string labcount = "0";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
           GetList=InitDate();
        }
    }

    public string InitDate()
    {   
        StringBuilder sb = new StringBuilder();
        string url = UrlGet.Get("test/73proxy.ashx?json=1&id=1&t=&p=&from=0&to=2&pj=airport2&c=32&iswhich=blue");
        var lst = Newtonsoft.Json.JsonConvert.DeserializeObject<List<StockEntity>>(url);
       
        sb.AppendFormat("<table width=\"548px\" cellpadding=\"0\" cellspacing=\"0\">");
        if (lst == null)
        {
            sb.AppendFormat("<tr colspan=\"5\"><td  style=\"padding-left:230px;padding-top:60px\">--暂无相关数据--</td></tr>");
            sb.AppendFormat("</table>");
            return sb.ToString();
        }
        lst = lst.OrderByDescending(x=>x.D).ToList();
        int _totalCount = 0;
        int _pagesize = 6;
        int _totalPage = 0;
        int page = ToInt(Request["page"], 1);

        _totalCount = lst.Count();
        labcount = _totalCount + ""; //入选英雄榜的数量
        if (_totalCount > 0)
        {
            if ((_totalCount % _pagesize) == 0)
                _totalPage = _totalCount / _pagesize;
            else
                _totalPage = (int)(_totalCount / _pagesize) + 1;
        }

        if (page == 0)
            page = 1;
        if (page > _totalPage)
            page = _totalPage;
        int _index = (page - 1) * _pagesize;
        int _end = page * _pagesize;
        if (page == _totalPage && (_totalCount % _pagesize) != 0)
            _end = (page - 1) * _pagesize + _totalCount % _pagesize;

       
        string Ptime="";
        for (int j = _index; j < _end; j++)
        {    
            if(lst[j].D!="" ||lst[j].D!=null)
            {
               Ptime=lst[j].D.Substring(0,2)+"/"+lst[j].D.Substring(2,2)+"/"+lst[j].D.Substring(4,2);
            }
            sb.AppendFormat("<tr  style=\"height:15px;line-height:15px;\">");
            sb.AppendFormat("<td class=\"wh1\">" + (j + 1) + "</td><td class=\"wh2\">" + lst[j].N + "</td>");
            sb.AppendFormat("<td class=\"wh3\">" + lst[j].C + "</td><td class=\"wh4\">" + lst[j].FSY + "%</td><td class=\"wh5\">" + Ptime + "</td>");
            sb.AppendFormat("</tr>");
            sb.AppendFormat("<tr><td colspan=\"5\">");
            sb.AppendFormat("<div class=\"clr\"></div>");
            sb.AppendFormat("<div class=\"xian\"></div>");
            sb.AppendFormat("</td></tr>");

        }
        sb.AppendFormat("</table>");
        if (_totalPage > 1)
            strPage = "<div class=\"news_next\" style=\"white-space:nowrap\">" + PageHelper.fy(_totalCount, _pagesize, page, Request.Url.AbsoluteUri) + "</div>";


        return sb.ToString();
    
    }
    public class StockEntity
    {
        public string N //股票名称
        { 
           get; 
           set; 
        }
        public string C //股票代码
        {
           get;
           set; 
        }
        public string D  //入榜日期
        {
            get;
            set;
        }
      
        public string PIN //入选价格
        {
            get;
            set;
        }
        public string FSY  //最大收益
        {
            get;
            set;
        }
    }

    public int ToInt(object obj, int v)
    {
        try
        {
            v = int.Parse(obj.ToString());
        }
        catch { }
        return v;
    }
}